class UsersController < ApplicationController

    def index
        @users = User.all
    end

    def new
        @user = User.new
    end

    def create
        @user = User.new(params[:user].permit(:first_name, :last_name, :email_address, :password))
        if @user.save
            redirect_to users_path 
        else
            render :new
        end
    end

    def destroy
        @user = User.find(params[:id])
        @user.destroy
        redirect_to users_path
    end

    def edit
        @user = User.find(params[:id])
    end

    def update
        @user = User.find(params[:id])
        if @user.update(params[:user].permit(:first_name, :last_name, :email_address, :password))
            redirect_to users_path
        else
            render 'edit'
        end
    end

    def show
        @user = User.find(params[:id])
    end
end
